#include "communicationprotocol.h"

CommunicationProtocol::CommunicationProtocol()
{

}

QByteArray CommunicationProtocol::VisionDatasPakeage(int ID, float visiondata)
{
    QByteArray DatasPakeage;
    char chr4[4];
    DatasPakeage[0]=Chasis_ID;//数据包的第一位：底盘单片机ID
    switch (ID) {
    case ID_Vision_dx:
        DatasPakeage[1]=ID_Vision_dx;//数据包的第二位，数据ID:视觉巡线dx
        mymath.FloatTo4Bytes(visiondata,chr4);
        DatasPakeage[2]=chr4[0];
        DatasPakeage[3]=chr4[1];
        DatasPakeage[4]=chr4[2];
        DatasPakeage[5]=chr4[3];
        DatasPakeage[6]=mymath.CRC8Table_32(chr4);//数据包的最后一位：CRC-8校验码
        return DatasPakeage;
        break;
    case ID_Vision_dy:
        DatasPakeage[1]=ID_Vision_dy;//数据包的第二位，数据ID:视觉巡线dy
        mymath.FloatTo4Bytes(visiondata,chr4);
        DatasPakeage[2]=chr4[0];
        DatasPakeage[3]=chr4[1];
        DatasPakeage[4]=chr4[2];
        DatasPakeage[5]=chr4[3];
        DatasPakeage[6]=mymath.CRC8Table_32(chr4);//数据包的最后一位：CRC-8校验码
        return DatasPakeage;
        break;
    case ID_Vision_angle:
        DatasPakeage[1]=ID_Vision_angle;//数据包的第二位，数据ID:视觉巡线angle
        mymath.FloatTo4Bytes(visiondata,chr4);
        DatasPakeage[2]=chr4[0];
        DatasPakeage[3]=chr4[1];
        DatasPakeage[4]=chr4[2];
        DatasPakeage[5]=chr4[3];
        DatasPakeage[6]=mymath.CRC8Table_32(chr4);//数据包的最后一位：CRC-8校验码
        return DatasPakeage;
        break;
    default:
        return 0;
        break;
    }
}
